/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-27 16:02:34
 * @LastEditTime: 2022-06-14 13:27:05
 */
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import CustomerMgr from '@/biz/customer/customerOpt.js';

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'customerName',
        title: '客户姓名',
        minWidth: 200,
        header: {
          filter: {
            title: '客户姓名',
            key: 'customerName',
            placeholder: '请输入客户姓名',
            input: {}
          }
        },
      },
      {
        field: 'customerPhone',
        minWidth: 130,
        header: {
          filter: {
            title: '手机号码',
            key: 'customerPhone',
            placeholder: '请输入手机号码',
            input: {}
          }
        }
      }, {
        field: 'userName',
        title: '归属顾问',
        minWidth: 180,
        header: {
          filter: nameOpt.createPeople({
            key: 'userName',
            title: '归属顾问',
            placeholder: '请输入顾问姓名或工号',
            validate: 3,
            to: (info) => {
              return {
                userName: info.name,
                userId: info.userId
              }
            }
          })
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: `${params.row.userName}(${params.row.workNo})`
            })
          }
        }
      }, {
        field: 'wechat',
        title: '微信号',
        minWidth: 200,
        header: {
          filter: {
            title: '微信号',
            key: 'wechat',
            placeholder: '请输入微信号',
            input: {}
          }
        },
      }, {
        field: 'intentionLevel',
        minWidth: 120,
        header: {
          filter: {
            title: '意向等级',
            key: 'intentionLevel',
            placeholder: '请选择意向等级',
            load: (o) => {
              o.select.options = CustomerMgr.intentionLevel()
            },
            select: {
              options: [],
              multiple: true,
              filterable: true,
            }
          }
        }
      },

      {
        field: 'isBindStr',
        minWidth: 120,
        header: {
          filter: {
            title: '是否绑定',
            key: 'isBind',
            placeholder: '请选择是否绑定',
            select: {
              options: [
                { key: 1, value: '是' },
                { key: 0, value: '否' },
              ],
            }
          }
        },
        // slots: {
        //   default: (params, h) => {
        //     return [h('div', params.row.buildingType == 2 ? '离案' : '在案')]
        //   }
        // }
      },

      {
        field: 'createTime',
        minWidth: 150,
        title: '创建时间',
        header: {
          filter: dateOpt.range({
            title: '创建时间',
            startKey: 'createStartTime',
            endKey: 'createEndTime',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.createStartTime, val
                  .createEndTime).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('签约日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.createStartTime, val
                .createEndTime).Y >= 2)
            }
          }),
        },
      },

      {
        field: 'customerFeature',
        minWidth: 120,
        title: '特征描述',
      },
      {
        field: 'featurePhoto',
        minWidth: 200,
        title: '特征附件',
        slots: {
          default: (params, h) => {
            let img = {
              event: 'lookImg',
              src: params.row.featurePhoto[0] ? params.row.featurePhoto[0] : '',
              data: params.row.featurePhoto
            }
            // return table.cell.img(_this, h, img, true)
            return params.row.featurePhoto?table.cell.img(_this, h, img, true):'-'
          }

        }
      },

      {
        title: '操作',
        fixed: 'right',
        width: 100,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []
            btns.push({
              title: '查看详情',
              event: 'viewClick',
              data: params.row
            })

            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }

}

export default Column